package top.yangguangmc.smart_scheduling.table.excel;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;

import java.util.ArrayList;
import java.util.List;

public class DataListener extends AnalysisEventListener<ExcelData> {
    List<ExcelData> list = new ArrayList<>();

    /**
     * 解析每一条数据都会调用
     *
     * @param data    解析到的数据
     * @param context ?
     */
    @Override
    public void invoke(ExcelData data, AnalysisContext context) {
        System.out.println("解析到一条数据：" + data);
        list.add(data);
    }

    /**
     * 全部解析完后调用
     *
     * @param context ?
     */
    @Override
    public void doAfterAllAnalysed(AnalysisContext context) {
        StringBuilder sb = new StringBuilder();
        for (ExcelData data : list) {
            sb.append(data);
            sb.append(";\n");
        }
        sb.delete(sb.length() - 3, sb.length() - 1);
        System.out.println("所有数据：\n" + sb);
    }
}
